//
//  SLChangePswdVC.m
//  SlockApp
//
//  Created by 凯朱 on 2024/7/25.
//

#import "SLChangePswdVC.h"

@interface SLChangePswdVC ()

@end

@implementation SLChangePswdVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUpSubViews];
}

-(void)setUpSubViews{
    self.title = kLocalString(@"Change password");
   
    _sureBtn.btnStyle = 1;
    [_sureBtn setTitle:kLocalString(@"Change password") forState:UIControlStateNormal];
    self.bgView1.layer.cornerRadius = 20;
    self.bgView1.layer.masksToBounds = YES;
    self.bgView2.layer.cornerRadius = 20;
    self.bgView2.layer.masksToBounds = YES;
    self.bgView3.layer.cornerRadius = 20;
    self.bgView3.layer.masksToBounds = YES;
  
    
    _tipLbl1.text = kLocalString(@"Current password");
    _tipLbl2.text = kLocalString(@"New password");
    _tipLbl3.text = kLocalString(@"Confirm new password");
    _tf1.secureTextEntry = YES;
    _tf2.secureTextEntry = YES;
    _tf3.secureTextEntry = YES;
    [_tf1 setPlaceholderWithPlaceholderText:kLocalString(@"Enter current password") withColor:KColor_placeholdar withFont:kFont(16)];
    [_tf2 setPlaceholderWithPlaceholderText:kLocalString(@"Enter new password") withColor:KColor_placeholdar withFont:kFont(16)];
    [_tf3 setPlaceholderWithPlaceholderText:kLocalString(@"Confirm new password") withColor:KColor_placeholdar withFont:kFont(16)];
    [_tf1 showEyeBtn];
    [_tf2 showEyeBtn];
    [_tf3 showEyeBtn];
    
}

- (IBAction)sureAction:(id)sender {
    [_tf1 endEditing:YES];
    [_tf2 endEditing:YES];
    [_tf3 endEditing:YES];
    
    if (![_tf2.text checkPassword] || ![_tf3.text checkPassword]) {
        return;
    }
    
    if (![_tf2.text isEqualToString:_tf3.text]) {
        kShowToast(@"Two new passwords do not match");
        return;
    }
    
    kWeakSelf(self);
    [ZCTool showLoadingOnKeyWindow];
    NSDictionary *params = @{@"currentPassword":_tf1.text,
                             @"newPassword":_tf2.text,
                             @"confirmPassword":_tf3.text};
    [ZKHttpManager postWithPath:@"/msl_user/ChangePassword" params:params finished:^(BOOL isSuccessed, id  _Nonnull result, NSString * _Nonnull code, NSString * _Nonnull message) {
        [ZCTool hideLoadingOnKeyWindow];
        if (!isSuccessed) {
            kShowToast(message);
            return;
        }
        [weakself showSuccessViews];
    }];
    
}

-(void)showSuccessViews{
    __weak SLSuccessAlertView *alert = [SLSuccessAlertView viewFromXIB];
    kWeakSelf(self);
    [alert setBtnBlock:^(NSInteger btnIndex) {
        [alert removeFromSuperview];
        [weakself.navigationController popViewControllerAnimated:YES];
    }];
    [kAppWindow addSubview:alert];
}


@end
